package com.wlyuan.open.scanner.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wlyuan.open.scanner.application.annotation.DataScope;
import com.wlyuan.open.scanner.dao.entity.ContractIndexDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yuanjie
 * @since 2022-10-13
 */
public interface ContractIndexMapper extends BaseMapper<ContractIndexDO> {

    String QUERY_SQL = "SELECT a.Index_ID, a.Index_GUID, a.Index_Code, a.Index_Name, a.Index_Content, a.Index_PartACompanyID, a.Index_PartACompanyName, a.Index_PartAAddr, a.Index_PartAContact, a.Index_PartAPhone, a.Index_PartATime, a.Index_PartAConfirmer, a.Index_PartAConfirmTime, a.Index_PartBCompanyID, a.Index_PartBCompanyName, a.Index_PartBAddr, a.Index_PartBContact, a.Index_PartBPhone, a.Index_PartBTime, a.Index_PartBConfirmer, a.Index_PartBConfirmTime, a.Index_FromTime, a.Index_ToTime, a.Index_Status, a.Index_StatusTime, a.Index_Creator, a.Index_CreatorCompanyID, a.Index_CreateTime, a.Index_Invalid, a.Index_Comments, a.Index_Esignature, a.Index_PartBType, a.Index_ContractUrl, a.Index_ContractSigneUrl " +
            "FROM TMS_ContractIndex a ";

    /**
     * 合同列表
     *
     * @return
     */
    @Select(QUERY_SQL)
    @DataScope(column = "Index_PartACompanyID", alias = "a")
    List<ContractIndexDO> list();


    @Select(QUERY_SQL + " a.Index_CreatorCompanyID = #{tenantId}")
    @DataScope(column = "Index_PartACompanyID", alias = "a")
    List<ContractIndexDO> getByTenantId(Long tenantId);

    @Select("SELECT a.Index_ID FROM TMS_ContractIndex a WHERE a.Index_CreateTime >= #{startTime} and a.Index_CreateTime <= #{endTime}")
    List<Long> getByTime(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT a.Index_ID FROM TMS_ContractIndex a WHERE a.Index_PartACompanyID = #{tenantId} and a.Index_CreateTime >= #{startTime} and a.Index_CreateTime <= #{endTime}")
    List<Long> getByTenantIdTime(@Param("tenantId") Long tenantId, @Param("startTime") String startTime, @Param("endTime") String endTime);

}
